package io.cici.cc.mybatis.lite.sql_source.scripting.tagHandler;

import io.cici.cc.mybatis.lite.sql_source.scripting.XMLScriptBuilder;
import io.cici.cc.mybatis.lite.sql_source.scripting.tag.ForEachTag;
import io.cici.cc.mybatis.lite.sql_source.scripting.tag.MixedTag;
import io.cici.cc.mybatis.lite.sql_source.scripting.tag.Tag;

import java.util.List;

public class ForEachTagHandler implements TagHandler {
    private final XMLScriptBuilder xmlScriptBuilder;

    public ForEachTagHandler(XMLScriptBuilder xmlScriptBuilder) {
        this.xmlScriptBuilder = xmlScriptBuilder;
        // Prevent Synthetic Access
    }

    @Override
    public void handle(io.cici.cc.mybatis.lite.parse.Node nodeToHandle, List<Tag> tagList) {
        MixedTag mixedTag = xmlScriptBuilder.parseDynamicTags(nodeToHandle);
        String collection = nodeToHandle.getStringAttribute("collection");
        String item = nodeToHandle.getStringAttribute("item");
        String index = nodeToHandle.getStringAttribute("index");
        String open = nodeToHandle.getStringAttribute("open");
        String close = nodeToHandle.getStringAttribute("close");
        String separator = nodeToHandle.getStringAttribute("separator");
        ForEachTag forEachTag = new ForEachTag(xmlScriptBuilder.configuration, mixedTag, collection, index, item, open, close, separator);
        tagList.add(forEachTag);
    }
}
